package br.com.pixt;


import java.util.Calendar;

import org.ksoap2.serialization.SoapObject;


import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class Classes extends Activity 
{
	private static final String CATEGORIA = "ZAE - Classes";

	public Classes() 
	{
	}
	
	public void Agendar(int horas,int id) 
	{
		int minutos = horas;
		int minutosAntes = minutos-5;
		
		// Intent para disparar o broadcast
		Intent it = new Intent("NOTIFICACAO");
			
		Bundle params = new Bundle();
		params.putInt("IdCliente", id);
		params.putInt("intHoras",horas);
		
		it.putExtras(params);	
		try 
		{
		
			PendingIntent p = PendingIntent.getService(this, 0, it, 0);
		
			// Para executar o alarme depois de x segundos a partir de agora
			Calendar c = Calendar.getInstance();
			c.setTimeInMillis(System.currentTimeMillis());
			c.add(Calendar.MINUTE, minutos);
		
			// Agenda o alarme
			AlarmManager alarme = (AlarmManager) getSystemService(ALARM_SERVICE);
			long time = c.getTimeInMillis();
			alarme.set(AlarmManager.RTC_WAKEUP, time, p);	
		} 
		catch (Exception e) 
		{
			Log.e(CATEGORIA,"Agendar : "+ e.getMessage(), e);
		}					
	}
}
